<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>localStorage</h1>
    <button id="sava">sava</button>
    <button id="get">get</button>
    <button id="remove">remove</button>
    <button id="clear">clear</button>
    <script>
        let btn = document.getElementById('sava')
        btn.onclick = function(){
            const obj = {
                name:'张十三'
            }
            localStorage.setItem('user',JSON.stringify(obj))
        }
        let btn2 = document.getElementById('get')
        btn2.onclick = function(){
            const user = localStorage.getItem('user')
            console.log(JSON.parse(user));
        }
        let btn3 = document.getElementById('remove');
        btn3.onclick = function(){
            localStorage.removeItem('user')
        }
        let btn4 = document.getElementById('clear')
        btn4.onclick = function(){
            localStorage.clear()
        }
    </script>
</body>
</html>